package com.atguigu.gulimall.order.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要得数据
 */
@Data
public class OrderConfirmVo {

    List<MemberReceiveAddressTo> address; //收获地址

    // 所有选中得购物项
    List<OrderItemVo> items;

    //优惠券信息
    Integer integration;

//    BigDecimal total;  //总价

//    BigDecimal payPrice;  //应付价格

    Map<Long,Boolean> stock;

    String orderToken; //防重令牌

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : this.items) {
                BigDecimal count = new BigDecimal(item.getCount().toString());
                BigDecimal multiply = item.getPrice().multiply(count);
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public Integer getCount(){
        Integer num = 0;
        if(items!=null){
            for (OrderItemVo item : this.items) {
                num+=item.getCount();
            }
        }
        return num;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }


}
